import axios from 'axios'
import baseUrl from './global'
import {message} from 'antd'

const instance = axios.create({
    baseURL:baseUrl,
    timeout:15000
})

instance.interceptors.request.use((config)=>{
    return config
})

function request({url,data,method}){
    return new Promise((resolve,reject)=>{
        instance({
            url,
            method,
            data
        }).then(res=>{
            if (res.data.status===0) {
                resolve(res)
            } else if(res.data.status===1){
                message.error('用户名/密码不正确！')
            } else if(res.data.status===2){
                message.error('用户名不存在！')
            }
        }).catch(err=>{
            message.error(err.message)
        })
    })
}

export default request